package com.niujie.prototypemanage.utils;

import com.niujie.prototypemanage.pojo.LoginCodeEnum;
import com.niujie.prototypemanage.pojo.LoginProperties;
import com.wf.captcha.base.Captcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class CaptchaUtil {

    @Resource
    private LoginProperties loginProperties;

    public String getImg(){
        return loginProperties.getCaptcha().toBase64();
    }

    public String getCaptchaValue(){
        Captcha captcha = loginProperties.getCaptcha();
        String captchaValue = captcha.text();
        if (captcha.getCharType() - 1 == LoginCodeEnum.ARITHMETIC.ordinal() && captchaValue.contains(".")) {
            captchaValue = captchaValue.split("\\.")[0];
        }
        // 验证码信息
        return captchaValue;
    }
}
